home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / AIncludes / Threads.a < prev    next >
Encoding:
Text File  |  1998-08-17  |  10.6 KB  |  402 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    File:        Threads.a
  3. ;
  4. ;    Contains:    Thread Manager Interfaces.
  5. ;
  6. ;    Version:    Technology:    Mac OS 8
  7. ;                Release:    Universal Interfaces 3.2
  8. ;
  9. ;    Copyright:    © 1991-1998 by Apple Computer, Inc., all rights reserved.
  10. ;
  11. ;    Bugs?:        For bug reports, consult the following page on
  12. ;                the World Wide Web:
  13. ;
  14. ;                    http://developer.apple.com/bugreporter/
  15. ;
  16. ;
  17.     IF &TYPE('__THREADS__') = 'UNDEFINED' THEN
  18. __THREADS__ SET 1
  19.  
  20.     IF &TYPE('__MACTYPES__') = 'UNDEFINED' THEN
  21.     include 'MacTypes.a'
  22.     ENDIF
  23.     IF &TYPE('__MIXEDMODE__') = 'UNDEFINED' THEN
  24.     include 'MixedMode.a'
  25.     ENDIF
  26.     IF &TYPE('__ERRORS__') = 'UNDEFINED' THEN
  27.     include 'Errors.a'
  28.     ENDIF
  29.  
  30. ;  Thread states 
  31. ; typedef unsigned short                 ThreadState
  32.  
  33.  
  34. kReadyThreadState                EQU        0
  35. kStoppedThreadState                EQU        1
  36. kRunningThreadState                EQU        2
  37. ;  Error codes have been meoved to Errors.(pah) 
  38. ;  Thread environment characteristics 
  39. ; typedef void *                        ThreadTaskRef
  40.  
  41. ;  Thread characteristics 
  42. ; typedef unsigned long                 ThreadStyle
  43.  
  44.  
  45. kCooperativeThread                EQU        $00000001
  46. kPreemptiveThread                EQU        $00000002
  47. ;  Thread identifiers 
  48. ; typedef unsigned long                 ThreadID
  49.  
  50.  
  51. kNoThreadID                        EQU        0
  52. kCurrentThreadID                EQU        1
  53. kApplicationThreadID            EQU        2
  54. ;  Options when creating a thread 
  55. ; typedef unsigned long                 ThreadOptions
  56.  
  57.  
  58. kNewSuspend                        EQU        $01
  59. kUsePremadeThread                EQU        $02
  60. kCreateIfNeeded                    EQU        $04
  61. kFPUNotNeeded                    EQU        $08
  62. kExactMatchThread                EQU        $10
  63. ;  Information supplied to the custom scheduler 
  64. SchedulerInfoRec        RECORD 0
  65. InfoRecSize                 ds.l    1                ; offset: $0 (0)
  66. CurrentThreadID             ds.l    1                ; offset: $4 (4)
  67. SuggestedThreadID         ds.l    1                ; offset: $8 (8)
  68. InterruptedCoopThreadID     ds.l    1                ; offset: $C (12)
  69. sizeof                     EQU *                    ; size:   $10 (16)
  70.                         ENDR
  71. ; typedef struct SchedulerInfoRec *        SchedulerInfoRecPtr
  72.  
  73.  
  74.     IF TARGET_CPU_68K ** TARGET_RT_MAC_CFM THEN
  75. ;    The following UniversalProcPtrs are for CFM-68k compatiblity with
  76. ;    the implementation of the Thread Manager.
  77. ;
  78.  
  79. ; typedef UniversalProcPtr                 ThreadEntryProcPtr
  80.  
  81. ; typedef UniversalProcPtr                 ThreadSchedulerProcPtr
  82.  
  83. ; typedef UniversalProcPtr                 ThreadSwitchProcPtr
  84.  
  85. ; typedef UniversalProcPtr                 ThreadTerminationProcPtr
  86.  
  87. ; typedef UniversalProcPtr                 DebuggerNewThreadProcPtr
  88.  
  89. ; typedef UniversalProcPtr                 DebuggerDisposeThreadProcPtr
  90.  
  91. ; typedef UniversalProcPtr                 DebuggerThreadSchedulerProcPtr
  92.  
  93.     ELSE
  94. ;    The following ProcPtrs cannot be interchanged with UniversalProcPtrs because
  95. ;    of differences between 680x0 and PowerPC runtime architectures with regard to
  96. ;    the implementation of the Thread Manager.
  97.  
  98. ;  Prototype for thread's entry (main) routine 
  99. ; typedef void *                        voidPtr
  100.  
  101. ;  Prototype for custom thread scheduler routine 
  102. ;  Prototype for custom thread switcher routine 
  103. ;  Prototype for thread termination notification routine 
  104. ;  Prototype for debugger NewThread notification 
  105. ;  Prototype for debugger DisposeThread notification 
  106. ;  Prototype for debugger schedule notification 
  107.     ENDIF
  108.  
  109. ;  Thread Manager routines 
  110. ;
  111. ; pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  112. ;
  113.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  114.         Macro
  115.         _CreateThreadPool
  116.             move.w              #$0501,D0
  117.             dc.w                $ABF2
  118.         EndM
  119.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  120.         IMPORT_CFM_FUNCTION CreateThreadPool
  121.     ENDIF
  122.  
  123. ;
  124. ; pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  125. ;
  126.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  127.         Macro
  128.         _GetFreeThreadCount
  129.             move.w              #$0402,D0
  130.             dc.w                $ABF2
  131.         EndM
  132.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  133.         IMPORT_CFM_FUNCTION GetFreeThreadCount
  134.     ENDIF
  135.  
  136. ;
  137. ; pascal OSErr GetSpecificFreeThreadCount(ThreadStyle threadStyle, Size stackSize, short *freeCount)
  138. ;
  139.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  140.         Macro
  141.         _GetSpecificFreeThreadCount
  142.             move.w              #$0615,D0
  143.             dc.w                $ABF2
  144.         EndM
  145.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  146.         IMPORT_CFM_FUNCTION GetSpecificFreeThreadCount
  147.     ENDIF
  148.  
  149. ;
  150. ; pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  151. ;
  152.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  153.         Macro
  154.         _GetDefaultThreadStackSize
  155.             move.w              #$0413,D0
  156.             dc.w                $ABF2
  157.         EndM
  158.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  159.         IMPORT_CFM_FUNCTION GetDefaultThreadStackSize
  160.     ENDIF
  161.  
  162. ;
  163. ; pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  164. ;
  165.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  166.         Macro
  167.         _ThreadCurrentStackSpace
  168.             move.w              #$0414,D0
  169.             dc.w                $ABF2
  170.         EndM
  171.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  172.         IMPORT_CFM_FUNCTION ThreadCurrentStackSpace
  173.     ENDIF
  174.  
  175. ;
  176. ; pascal OSErr NewThread(ThreadStyle threadStyle, ThreadEntryProcPtr threadEntry, void *threadParam, Size stackSize, ThreadOptions options, void **threadResult, ThreadID *threadMade)
  177. ;
  178.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  179.         Macro
  180.         _NewThread
  181.             move.w              #$0E03,D0
  182.             dc.w                $ABF2
  183.         EndM
  184.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  185.         IMPORT_CFM_FUNCTION NewThread
  186.     ENDIF
  187.  
  188. ;
  189. ; pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  190. ;
  191.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  192.         Macro
  193.         _DisposeThread
  194.             move.w              #$0504,D0
  195.             dc.w                $ABF2
  196.         EndM
  197.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  198.         IMPORT_CFM_FUNCTION DisposeThread
  199.     ENDIF
  200.  
  201. ;
  202. ; pascal OSErr YieldToThread(ThreadID suggestedThread)
  203. ;
  204.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  205.         Macro
  206.         _YieldToThread
  207.             move.w              #$0205,D0
  208.             dc.w                $ABF2
  209.         EndM
  210.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  211.         IMPORT_CFM_FUNCTION YieldToThread
  212.     ENDIF
  213.  
  214. ;
  215. ; pascal OSErr YieldToAnyThread(void )
  216. ;
  217.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  218.         Macro
  219.         _YieldToAnyThread
  220.             clr.l               -(sp)
  221.             move.w              #$0205,D0
  222.             dc.w                $ABF2
  223.         EndM
  224.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  225.         IMPORT_CFM_FUNCTION YieldToAnyThread
  226.     ENDIF
  227.  
  228. ;
  229. ; pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  230. ;
  231.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  232.         Macro
  233.         _GetCurrentThread
  234.             move.w              #$0206,D0
  235.             dc.w                $ABF2
  236.         EndM
  237.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  238.         IMPORT_CFM_FUNCTION GetCurrentThread
  239.     ENDIF
  240.  
  241. ;
  242. ; pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  243. ;
  244.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  245.         Macro
  246.         _GetThreadState
  247.             move.w              #$0407,D0
  248.             dc.w                $ABF2
  249.         EndM
  250.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  251.         IMPORT_CFM_FUNCTION GetThreadState
  252.     ENDIF
  253.  
  254. ;
  255. ; pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  256. ;
  257.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  258.         Macro
  259.         _SetThreadState
  260.             move.w              #$0508,D0
  261.             dc.w                $ABF2
  262.         EndM
  263.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  264.         IMPORT_CFM_FUNCTION SetThreadState
  265.     ENDIF
  266.  
  267. ;
  268. ; pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  269. ;
  270.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  271.         Macro
  272.         _SetThreadStateEndCritical
  273.             move.w              #$0512,D0
  274.             dc.w                $ABF2
  275.         EndM
  276.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  277.         IMPORT_CFM_FUNCTION SetThreadStateEndCritical
  278.     ENDIF
  279.  
  280. ;
  281. ; pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  282. ;
  283.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  284.         Macro
  285.         _SetThreadScheduler
  286.             move.w              #$0209,D0
  287.             dc.w                $ABF2
  288.         EndM
  289.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  290.         IMPORT_CFM_FUNCTION SetThreadScheduler
  291.     ENDIF
  292.  
  293. ;
  294. ; pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  295. ;
  296.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  297.         Macro
  298.         _SetThreadSwitcher
  299.             move.w              #$070A,D0
  300.             dc.w                $ABF2
  301.         EndM
  302.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  303.         IMPORT_CFM_FUNCTION SetThreadSwitcher
  304.     ENDIF
  305.  
  306. ;
  307. ; pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  308. ;
  309.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  310.         Macro
  311.         _SetThreadTerminator
  312.             move.w              #$0611,D0
  313.             dc.w                $ABF2
  314.         EndM
  315.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  316.         IMPORT_CFM_FUNCTION SetThreadTerminator
  317.     ENDIF
  318.  
  319. ;
  320. ; pascal OSErr ThreadBeginCritical(void )
  321. ;
  322.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  323.         Macro
  324.         _ThreadBeginCritical
  325.             move.w              #$000B,D0
  326.             dc.w                $ABF2
  327.         EndM
  328.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  329.         IMPORT_CFM_FUNCTION ThreadBeginCritical
  330.     ENDIF
  331.  
  332. ;
  333. ; pascal OSErr ThreadEndCritical(void )
  334. ;
  335.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  336.         Macro
  337.         _ThreadEndCritical
  338.             move.w              #$000C,D0
  339.             dc.w                $ABF2
  340.         EndM
  341.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  342.         IMPORT_CFM_FUNCTION ThreadEndCritical
  343.     ENDIF
  344.  
  345. ;
  346. ; pascal OSErr SetDebuggerNotificationProcs(DebuggerNewThreadProcPtr notifyNewThread, DebuggerDisposeThreadProcPtr notifyDisposeThread, DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  347. ;
  348.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  349.         Macro
  350.         _SetDebuggerNotificationProcs
  351.             move.w              #$060D,D0
  352.             dc.w                $ABF2
  353.         EndM
  354.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  355.         IMPORT_CFM_FUNCTION SetDebuggerNotificationProcs
  356.     ENDIF
  357.  
  358. ;
  359. ; pascal OSErr GetThreadCurrentTaskRef(ThreadTaskRef *threadTRef)
  360. ;
  361.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  362.         Macro
  363.         _GetThreadCurrentTaskRef
  364.             move.w              #$020E,D0
  365.             dc.w                $ABF2
  366.         EndM
  367.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  368.         IMPORT_CFM_FUNCTION GetThreadCurrentTaskRef
  369.     ENDIF
  370.  
  371. ;
  372. ; pascal OSErr GetThreadStateGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  373. ;
  374.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  375.         Macro
  376.         _GetThreadStateGivenTaskRef
  377.             move.w              #$060F,D0
  378.             dc.w                $ABF2
  379.         EndM
  380.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  381.         IMPORT_CFM_FUNCTION GetThreadStateGivenTaskRef
  382.     ENDIF
  383.  
  384. ;
  385. ; pascal OSErr SetThreadReadyGivenTaskRef(ThreadTaskRef threadTRef, ThreadID threadToSet)
  386. ;
  387.     IF TARGET_OS_MAC ** TARGET_CPU_68K ** ¬ TARGET_RT_MAC_CFM THEN
  388.         Macro
  389.         _SetThreadReadyGivenTaskRef
  390.             move.w              #$0410,D0
  391.             dc.w                $ABF2
  392.         EndM
  393.     ELSEIF TARGET_OS_MAC ** TARGET_RT_MAC_CFM THEN
  394.         IMPORT_CFM_FUNCTION SetThreadReadyGivenTaskRef
  395.     ENDIF
  396.  
  397.     ENDIF ; __THREADS__ 
  398.  
  399.